// Copyright (C) 2009 Mihai Preda

package calculator;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

class HistoryEntry
{
    String mLine;
    String mEditLine; 
    String mResult;
    
    HistoryEntry(String text, String result)
    {
        mLine = text;
        mEditLine = text;
        mResult = (result == null ? "" : result);
    }

    HistoryEntry(DataInputStream inputStream) throws IOException
    {
        mLine = inputStream.readUTF();
        mEditLine = inputStream.readUTF();
        
        if (mEditLine.length() == 0)
            mEditLine = mLine;
            
        mResult = inputStream.readUTF();
    }

    void save(DataOutputStream outputStream) throws IOException
    {
        outputStream.writeUTF(mLine);
        outputStream.writeUTF(mEditLine.equals(mLine) ? "" : mEditLine);
        outputStream.writeUTF(mResult);
    }

    void onEnter()
    {
        mEditLine = mLine;
    }
}
